import pro from "./Property";
const {ccclass, property} = cc._decorator;

@ccclass
export default class Bag extends cc.Component {


    @property({displayName: "property脚本所在节点", tooltip: "property脚本所在节点", type: pro})
    property: pro = null;


    @property({type: cc.Node, displayName: "背包界面UI", tooltip: "背包界面UI"})
    UI_bag: cc.Node = null;

    @property({type: cc.Node, displayName: "装备武器按钮", tooltip: "装备武器按钮"})
    btn_equip: cc.Node[] = [];

    
    onLoad () {
        let self = this;

        // for循环给每个装备武器按钮绑定事件
        for (let i = 0; i < this.btn_equip.length; i++) {
            this.btn_equip[i].on(cc.Node.EventType.TOUCH_START, function () {
                // 存储武器数据
                cc.sys.localStorage.setItem("weapon", i + 1);
                cc.log("已经装备了", i + 1, "号武器");

                // 进行隐藏和显示
                self.property.check();
            }, this);          
        }
    }




    // 打开背包界面
    open () {
        this.UI_bag.active = true;
    }

    // 关闭背包界面
    close () {
        this.UI_bag.active = false;
    }


}
